pro test_dist

  ; set device
  set_plot,'z',/copy
  loadct,1
  tvlct,255,0,0,1
  tvlct,0,255,0,2
  tvlct,0,0,255,3
  tvlct,red,green,blue,/get

  angle = Dindgen(101) / 100 * !dpi
  degrees = angle * 180 / !dpi
  dqv = Cos(angle)
  N = 100
  d0 = 0.04d
  logSigma = 1.5d
  GenLogNormal,N_r,r,N=N,D0=d0,logSigma=logSigma
  size_r = n_elements(r)
  dr = r[1:size_r -1] - r[0:size_r - 2]
  sum = total(n_r[0:size_r-2] * dr)
  print,sum
  ; test junge distribution
  n_lambda = 10
  lambda = findgen(n_lambda)/n_lambda * 1 + 0.2
;  lambda = [0.4, 0.6, 1.0, 2.0, 5.0, 10.0]
  Cm = DComplex(1.33, -0.1)

  C  = 100d
  N_junge = 1d3
  nu = [4.0, 3.5, 3.0, 2.5]
  n_nu = n_elements(nu)
  Kxt=fltarr(n_lambda,n_nu)
  Kbk=fltarr(n_lambda,n_nu)
  Ksc=fltarr(n_lambda,n_nu)
  eta = fltarr(n_lambda,101,n_nu)

  r = dindgen(1000)/1000 * 1 + 0.04
  dr = r[1]-r[0]
;  print,dr
  for i_nu = 0, n_nu -1 do begin
    n_r = junge_r(C,nu[i_nu],r)
;    plot,r,n_r,/xlog,/ylog
    tmpN = total(n_r)*dr
    print,'junge N=',tmpN
    C = C * N_junge / tmpN
    n_r = junge_r(C,nu[i_nu],r)
    print,'junge N=',total(n_r)*dr

    for i = 0, n_lambda-1 do begin
      mie_dist,n_r,r,lambda[i],Cm,dqv=dqv,tmpKxt,tmpKsc,tmpKbk,tmpeta
      Kxt[i,i_nu]=tmpKxt
      Kbk[i,i_nu]=tmpKbk
      Ksc[i,i_nu]=tmpKsc
      eta[i,*,i_nu] = tmpeta
    endfor
  endfor
  plot,lambda,Kbk[*,0],/xlog,/ylog
  for i=1,n_nu-1 do begin
;    icolor = 'FFFFFF'x - i * 'FFFFFF'x/(n_nu+2)
;    print,icolor
    oplot,lambda,Kbk[*,i];,color=icolor
  endfor
  write_png,'~/bk_lambda.png',TVRD()

  plot,degrees,eta[0,*,0],/ylog
  oplot,degrees,eta[9,*,0],linestyle=2
  for i=1,n_nu-1 do begin
    oplot,degrees,eta[0,*,i],color=i
    oplot,degrees,eta[9,*,i],linestyle=2,color=i
  endfor
  write_png,'~/eta0.png',TVRD(),red,green,blue

;  shade_surf,eta
;  write_png,'~/eta.png',TVRD()

end

